﻿Chenxin.UI.WorkReport=Chenxin.extend(Chenxin.UI.PageCommon,{
    autoInitForm:false,
    actionUrl:'/service/WorkReportSearch.ashx',
    createSearch:function(){
		return new Chenxin.UI.WorkReportSearch({
			scope:this,
			afterGetParamJson:function(data){
			    data.op='search';
            }
		});
	},
	createGrid: function() {
        return new Chenxin.UI.Pagination({
			actionUrl:this.actionUrl,
            id: 'allGrid',
            renderTo: 'all_table',
            pageSize: 15,
			data:{op:'search',type:'unreaded'},
			autoLoad:true
        });
    },
    initEvent: function() {
        var _this = this;
        _this.strckname='unreaded';

        //删除点击事件
        $('#btn_del').click(function(){
            _this.dellist(_this.strckname);
	    });
	    
	    //刷新点击事件
        $('#btn_refresh').click(function(){
	        _this.grid.reload({op:'search',type:''+_this.strckname+''},true);
	    });
	    
	    //恢复点击事件
	    $('#btn_restore').click(function(){
	        _this.restorelist(_this.strckname);
	    });
	    
        //未读点击事件
	    $('#aunReaded').click(function(){
	        $("#lireceivername").hide();
	        $("#lilreceivername").hide();
	        $("#lisendername").show();
	        $("#lilsendername").show();
	        _this.grid.reload({op:'search',type:'unreaded'},true);
	        _this.strckname='unreaded';
	        $("#btn_restore").hide();

	    });
	    
	    //已读点击事件
	    $('#aisReaded').click(function(){
	        $("#lireceivername").hide();
	        $("#lilreceivername").hide();
	        $("#lisendername").show();
	        $("#lilsendername").show();
	        _this.grid.reload({op:'search',type:'isreaded'},true);
	        _this.strckname='isreaded';
	        $("#btn_restore").hide();
	    });
	    
	    //发件箱点击事件
	    $('#aoutBox').click(function(){
	        $("#lireceivername").show();
	        $("#lilreceivername").show();
	        $("#lisendername").hide();
	        $("#lilsendername").hide();
	       	_this.grid.reload({op:'search',type:'outbox'},true);
	       	_this.strckname='outbox';
	        $("#btn_restore").hide();
	    });
	    
	    //垃圾箱点击事件
	    $('#adustBin').click(function(){
	    	$("#lireceivername").hide();
	        $("#lilreceivername").hide();
	        $("#lisendername").show();
	        $("#lilsendername").show();
	        _this.grid.reload({op:'search',type:'dustbin'},true);
	        _this.strckname='dustbin';
	        $("#btn_restore").hide();
	    });
	    
	    //全选(反选)点击事件
	    $('#lblck').live('click',function(){
            $("input[name="+_this.strckname+"ck]").attr('checked',$(':checkbox',this).attr('checked'));
        });
        
        //详情点击事件
        $('#btndetail').live('click',function(){
            if(_this.strckname!='outbox')
            {
	            _this.detail(this.name);
	        }
	    });
	    
        //附件点击事件
        $('#abtnreply').live('click',function(){
            /*Chenxin.ajax({
                type: "post",
                dataType: "json",
                url: _this.actionUrl,
                data: { op: 'download', modelid: this.name}
            });*/
        });
        
        /*$("#showMessager").click(function(){
		    $.popupmsg.show({
                title:'测试用消息标题。',
                text:'随便写写无所谓随便写写无所谓随便写写无所谓随便写写无所谓随便写写无所谓随便写写无所谓.',
                time:3100,
                type:'fade',
                txt:'消息列表'
            });
	    });*/
    },
    dellist: function(op) {
        var _this = this;
        var id = "";
        $(':checkbox:checked').each(function() {
            if (this.name == op+'ck') {
                if (id == '') {
                    id += this.value;
                } else {
                    id += "," + this.value;
                }
            }
        });
        if (!id) {
            alert('请选择至少一条记录！');
            return;
        }
        if (confirm('确定要删除选中记录吗？')) {
            Chenxin.ajax({
                type: "post",
                dataType: "json",
                url: this.actionUrl,
                data: { op: 'dellist', modelid: id, type:op },
                onSuccess: function(data, msg) {
                    alert(msg);
                    if (_this.grid) {
                        _this.grid.reload();
                    }
                    if (this.afterDelSucc) {
                        _this.afterDelSucc.call(_this, data, msg);
                    }
                }
            });
        }
    },
    restorelist: function(op){
        var _this = this;
        var id = "";
        $(':checkbox:checked').each(function() {
            if (this.name == op+'ck') {
                if (id == '') {
                    id += this.value;
                } else {
                    id += "," + this.value;
                }
            }
        });
        if (!id) {
            alert('请选择至少一条记录！');
            return;
        }
        if (confirm('确定要恢复选中记录吗？')) {
            Chenxin.ajax({
                type: "post",
                dataType: "json",
                url: this.actionUrl,
                data: { op: 'restorelist', modelid: id},
                onSuccess: function(data, msg) {
                    alert(msg);
                    if (_this.grid) {
                        _this.grid.reload();
                    }
                    if (this.afterDelSucc) {
                        _this.afterDelSucc.call(_this, data, msg);
                    }
                }
            });
        }
    },
    detail:function(op){
        var _this = this;
        Chenxin.ajax({
            type: "post",
            dataType: "json",
            url: this.actionUrl,
            data: { op: 'setisread', modelid: op},
            onSuccess: function(data, msg) {
                window.location.href = "WorkReportDetailInfo.aspx?RecordId="+msg+"";
            }
        });
    },
    initarg:function(){
        var _this = this;
        var arg = '';
        var data = {op:'search',type:_this.strckname,tag:'1'};
        
        if($("#txtReceiverName").val().length > 0){
            arg='接收对象:'+$("#txtReceiverName").val()+',';
            data.receivername=$("#txtReceiverName").val();      
        }else{
            data.receivername='';      
        }
        
        if($("#txtSenderName").val().length > 0){
            arg+='发件人:'+$("#txtSenderName").val()+',';     
            data.sendername=$("#txtSenderName").val();      
        }else{
            data.sendername='';      
        }
        
        if($("#txtSendTime").val().length > 0){
            arg+='发件时间:'+$("#txtSendTime").val()+',';      
            data.sendtime=$("#txtSendTime").val();      
        }else{
            data.sendtime='';      
        }
        
        if($("#txtSubject").val().length > 0){
            arg+='报告主题:'+$("#txtSubject").val()+',';    
            data.subject=$("#txtSubject").val();      
        }else{
            data.subject='';      
        }
   
        //$("#txtsearchbox").val(arg.substr(0,arg.length-1));
        //_this.grid.reload(data,true);
    },
	initComponent:function(){
	    Chenxin.UI.WorkReport.superclass.initComponent.call(this);
	}
}); 

/**
*查询面板
*/
Chenxin.UI.WorkReportSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id:'workreport_search',
	initEvent:function(){
		var _this=this; 
        $("#btnsearch").click(function(){
		    //_this.scope.initarg();
		    var data = _this.scope.search.getParamJson();
		    data.type=_this.scope.strckname;
		    data.tag = '1';
		    _this.scope.reloadGrid(data);
		});
        
        //条件
        $("#txtsearchbox").keyup(function(){
            _this.scope.grid.reload({op:'search',type:_this.scope.strckname,arg:$("#txtsearchbox").val(),tag:'0'},true);
        });
        //条件-得到焦点
        $("#txtsearchbox").focus(function(){
            if(!$("#txtsearchbox").val().isBlank())
            {
                $("#txtsearchbox").val('');
                _this.scope.grid.reload({op:'search',type:_this.scope.strckname,arg:$("#txtsearchbox").val(),tag:'0'},true);
            } 
        });

        //接收对象
        $("#txtReceiverName").keyup(function(){
            _this.scope.initarg();
        });
        
        //发件人
        $("#txtSenderName").keyup(function(){
            _this.scope.initarg();
        });
        
        //发件时间-得到焦点
        $("#txtSendTime").focus(function(){
            WdatePicker({oncleared:function(){_this.scope.initarg();},onpicked:function(){_this.scope.initarg();}});
        });
        //发件时间-失去焦点
        $("#txtSendTime").blur(function(){
            _this.scope.initarg();
        });
        //报告主题
        $("#txtSubject").keyup(function(){
            _this.scope.initarg();
        });
        
        //报告内容
        $("#txtContent").keyup(function(){
            _this.scope.initarg();
        });
	},
	createComboList: function() {
	    var senduser = new Chenxin.UI.UserTreeCombo({
            textBoxId: 'txtSenderName',
            required: true,
            name: 'senduserid'
        });
        
        var userreceiver = new Chenxin.UI.UserTreeCombo({
            textBoxId: 'txtReceiverName',
            required: true,
            name: 'userreceiverid'
        });
        return [senduser,userreceiver]
	},
    initComponent: function() {
        Chenxin.UI.WorkReportSearch.superclass.initComponent.call(this);
    }
});

$(document).ready(function() {
    $('#container-1 > ul').tabs();
    $("#txtsearchbox").val('');
    this.WorkReport = new Chenxin.UI.WorkReport();
});